package mypackage
{
	import flash.display.Sprite;
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.net.XMLSocket;
	
	import mx.controls.Button;
	
	public class websocket extends Sprite
	{
		public var _socket:XMLSocket;
		public var _btn:Button;
		
		public function websocket()
		{
			_socket = new XMLSocket();
			_socket.addEventListener(Event.CONNECT,onConnect);
			_socket.addEventListener(DataEvent.DATA,onData);
		}
		
		public function addBtn(btn:Button):void
		{
			_btn = btn;
		}
		public function connect():void
		{
			_btn.label = "OK";
			_socket.connect("192.168.1.110",8888);
		}
		
		public function close():void
		{
			_socket.close();
		}
		
		public function sendData(s:String):void
		{
			_socket.send(s);
		}
		
		public function onData(evt:DataEvent):void
		{
			//此处回调一个函数，当收到消息直接放到玩家的屏上去
		}
		
		public function onConnect(evt:Event):void
		{
		}

	}
}